package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class BestTimeToBuyAndSellStockWithTransactionFee {
    // 2022-08-29 13:48:38
    public static void main(String[] args) {
        Solution solution = new BestTimeToBuyAndSellStockWithTransactionFee().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int maxProfit(int[] prices, int fee) {
            int min = prices[0];

            int ans = 0;
            for (int i = 1; i < prices.length; i++) {
                if (prices[i] < min) {
                    min = prices[i];
                }
                if (prices[i] - min - fee > 0) {
                    ans += (prices[i] - min - fee);
                    min = prices[i] - fee;
                }
            }
            return ans;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}